<script setup lang="ts">
import MicroButton from "@/components/WebRTCService/components/MicroButton.vue";
import VideoButton from "@/components/WebRTCService/components/VideoButton.vue";
import {useDevice} from './use-device';

const {
  openMicro,
  closeMicro,
  videoRef,
  openVideo,
  closeVideo,
  openScreen,
  closeScreen,
  hasAudioInput,
  hasVideoInput,
  hasScreenInput,
  tip
} = useDevice()

</script>

<template>
  <div class="container">
    <div class="video-wrapper">
      <video class="video" ref="videoRef" autoplay playsinline muted></video>
      <div class="tip">{{tip}}</div>
      <div class="bottom-wrapper">
        <!-- 当麦克风已开启时禁用打开按钮 -->
        <MicroButton :disabled="hasAudioInput" @open="openMicro" @close="closeMicro"/>
        <!-- 当摄像头已开启时禁用打开按钮 -->
        <VideoButton :disabled="hasVideoInput" @open="openVideo" @close="closeVideo"/>
        <!-- 当屏幕共享已开启时禁用打开按钮 -->
        <ScreenShareButton :disabled="hasScreenInput" @open="openScreen" @close="closeScreen"/>
      </div>
    </div>
  </div>
</template>


<style scoped lang="scss">
.container{
  width: 100%;
  height: 100%;
  display: flex;
  overflow: hidden;  // 防止内容溢出
  background-color: black;
}

.video-wrapper{
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;  // 隐藏溢出部分

  video{
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  .bottom-wrapper{
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 80px;
    background: rgba(0,0,0,0.5);
    gap: 15px;
  }
}
.tip{
  position: absolute;
  top: 89%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 20px;
  text-align: center;
}
</style>
